#ifndef DECODE_H
#define DECODE_H

#include "data.h"

extern "C" {
    #include <libavcodec/avcodec.h>
    #include <libavutil/avutil.h>
    #include <libswscale/swscale.h>
    #include <libavutil/imgutils.h>
    #include <libavutil/opt.h>
}

class Decode
{
public:
    typedef boost::shared_ptr<Decode> DecodePtr;

    Decode();
    ~Decode();
    int decodeData(Data::DataPtr data);
    void pgm_save(unsigned char *buf,
                  int wrap, int xsize,
                  int ysize, char *filename);

private:
    Decode(const Decode& d);
    Decode& operator=(const Decode&);

    AVCodec *codec;
    AVCodecContext *c;
    int frame_count;
    FILE *f;
    AVFrame *frame;
//    uint8_t inbuf[INBUF_SIZE + FF_INPUT_BUFFER_PADDING_SIZE];
    AVPacket avpkt;
    const char *outfilename;
    struct SwsContext *sws_ctx;
    u_int8_t* tmp_data[4];
    int tmp_linesize[4];
    int reslut_size;
};

#endif // DECODE_H
